package com.ocom.devicehttp.controller;

import com.ocom.common.constant.MachineHttpUrl;
import com.ocom.common.request.payhandle.AlipayAuthInfoRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.JsonResponse;
import com.ocom.devicehttp.feign.machine.PayoperFeignService;
import com.ocom.devicehttp.service.MachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class MachineController {

    @Autowired
    private MachineService machineService;

    @Autowired
    private PayoperFeignService payoperFeignService;

    /*
     * @Description:签到
     * @Author: lu
     * @Date: 2022/3/24 16:33
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_PostSign)
    public JsonResponse sign(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.sign(map);
        return jsonResponse;
    }

    /*
     * @Description:心跳
     * @Author: lu
     * @Date: 2022/3/24 16:34
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_PostHeartbeat)
    public JsonResponse Heartbeat(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.Heartbeat(map);
        return jsonResponse;
    }

    /*
     * @Description: 设备参数更新
     * @Author: lu
     * @Date: 2022/3/24 17:15
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_PostMachinePara)
    public JsonResponse MachinePara(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.MachinePara(map);
        return jsonResponse;
    }

    //设备参数通知
    @PostMapping(MachineHttpUrl.URL_PostMachineParaResult)
    public JsonResponse machineParaResult(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.machineParaResult(map);
        return jsonResponse;
    }

    /*
     * @Description: 白名单下发
     * @Author: lu
     * @Date: 2022/6/27 9:45
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_WhiteList)
    public JsonResponse whiteList(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.whiteList(map);
        return jsonResponse;
    }

    /*
     * @Description:白（黑）名单更新结果
     * @Author: lu 
     * @Date: 2022/6/28 15:33
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_WhiteListResult)
    public JsonResponse whiteListResult(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.whiteListResult(map);
        return jsonResponse;
    }

    /*
     * @Description:离线码解码密钥更新
     * @Author: lu 
     * @Date: 2022/7/8 15:52
     * @param map:  
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_DecodeKey)
    public JsonResponse decodeKey(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.decodeKey(map);
        return jsonResponse;
    }

    /*
     * @Description: 离线码解码密钥更新结果通知
     * @Author: lu
     * @Date: 2022/7/15 15:17
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_DecodeKeyResult)
    public JsonResponse decodeKeyResult(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.decodeKeyResult(map);
        return jsonResponse;
    }


    /*
     * @Description:获取风控
     * @Author: lu
     * @Date: 2022/7/15 15:37
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_FkConfig)
    public JsonResponse fkConfig(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.fkConfig(map);
        return jsonResponse;
    }

    /*
     * @Description:获取风控成功通知
     * @Author: lu
     * @Date: 2022/7/15 15:38
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_FkConfigResult)
    public JsonResponse fkConfigResult(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.fkConfigResult(map);
        return jsonResponse;
    }

    //升级更新结果通知
    @PostMapping(MachineHttpUrl.URL_UpgradeFinish)
    public JsonResponse upgradeFinish(@RequestBody Map<String,Object> map) {
        return JsonResponse.success();
    }



    @PostMapping(MachineHttpUrl.URL_faceLogin)
    public JsonResponse faceLogin(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.faceErr(map);
        return jsonResponse;
    }


    @PostMapping(MachineHttpUrl.URL_adPic)
    public JsonResponse adPic(@RequestBody Map<String,Object> map) {
//        List<String> list =new ArrayList<>();
//        list.add("http://47.107.69.158:9002/img-library/0f8d78187a4f3a228adb2ad1184e185.png");
//        list.add("http://47.107.69.158:9002/img-library/1c28d7f7b001a2bb3bf19d9815000c8.png");
//        return JsonResponse.success(list);

        JsonResponse jsonResponse=machineService.adPic(map);
        return jsonResponse;
    }

    @PostMapping(MachineHttpUrl.URL_pictureurl)
    public JsonResponse pictureurl(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.pictureurl(map);
        return jsonResponse;
    }

    //3.37 个人密码认证
    @PostMapping(MachineHttpUrl.URL_PasswordAuthentication)
    public JsonResponse passwordAuthentication(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.passwordAuthentication(map);
        return jsonResponse;
    }

    //3.40 菜单更新（MenuList）
    @PostMapping(MachineHttpUrl.URL_MenuList)
    public JsonResponse menuList(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.menuList(map);
        return jsonResponse;
    }


    //3.40 菜单更新（MenuList）
    @PostMapping(MachineHttpUrl.URL_MenuListResult)
    public JsonResponse menuListResult(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.menuListResult(map);
        return jsonResponse;
    }

    //3.42 设备上传人脸注册信息（RegisterInf）
    @PostMapping(MachineHttpUrl.URL_RegisterInf)
    public JsonResponse RegisterInf(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.RegisterInf(map);
        return jsonResponse;
    }

    //3.43 发送短信接口（SendSMS）
    @PostMapping(MachineHttpUrl.URL_SendSMS)
    public JsonResponse SendSMS(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.SendSMS(map);
        return jsonResponse;
    }

    //3.42支付宝机器初始化（alipayMachInit）
    @PostMapping(MachineHttpUrl.URL_AlipayMachInit)
    public JsonResponse alipayMachInit(@RequestBody Map<String,Object> map) {
        AlipayAuthInfoRequest request = new AlipayAuthInfoRequest();
        request.setMachNo((String) map.get("machNo"));
        request.setCompanyId(Long.parseLong(String.valueOf(map.get("companyID"))));
        Result result = payoperFeignService.getAlipayAuthInfo(request);
        JsonResponse jsonResponse;

        if (result.getCode()==200) {
            jsonResponse = JsonResponse.success("0000", result.getMsg(), result.getData());
        } else {
            jsonResponse = JsonResponse.error();
        }

        return jsonResponse;
    }


}
